package com.code.day10.Socketz;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
public class Client {
    public static void main(String[] args) throws IOException {
        //1.创建Socket对象，设置服务端ip跟端口号
        Socket socket = new Socket("127.0.0.1", 6666);
        //2.调用socket中的getOutputStream方法获取一个OutputStream对象用于写请求
        OutputStream os = socket.getOutputStream();
        os.write("ssss".getBytes());
        //3.调用socket中的getInputStream方法获取一个InputStream对象读取Server发过来的数据
        InputStream is = socket.getInputStream();
        byte[] buffer = new byte[1024];
        int len = is.read(buffer);
        System.out.println(new String(buffer, 0, len));
        //关闭资源
        is.close();
        os.close();
        socket.close();
    }
}
